home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI737.ASC < prev    next >
Text File  |  1992-02-25  |  8KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Resource Workshop                      NUMBER  :  737
  8.   VERSION  :  1.0
  9.        OS  :  WIN
  10.      DATE  :  February 25, 1992                        PAGE  :  1/5
  11.  
  12.     TITLE  :  Creating and Using Custom Fonts with Resource
  13.               Workshop
  14.  
  15.  
  16.  
  17.  
  18.   INTRODUCTION:
  19.  
  20.   One of the greatest features of Microsoft Windows is its ability
  21.   to allow applications to share system resources (fonts, printer
  22.   drivers, etc.).  This 'device independent' approach is a mixed
  23.   blessing to application developers:  While this capability makes
  24.   Windows work better for its users, it makes life a nightmare for
  25.   an application developer.
  26.  
  27.   This document addresses the issue of how to create a custom font,
  28.   to cause Windows to recognize it, and to actually use it in your
  29.   own applications.  It is divided into two sections:
  30.  
  31.         I.  Creating a custom font library
  32.  
  33.        II.  Using custom fonts in your applications
  34.  
  35.   This document assumes that you own Borland C++ 2.0.  It is
  36.   recommended that you own Resource Workshop as well.
  37.  
  38.   I. CREATING A CUSTOM FONT LIBRARY:
  39.  
  40.        Windows supports the use of  custom  fonts  by  allowing the
  41.        user (or an  application)  to install a 'font resource' into
  42.        the system font  pool.    A  font resource is a font library
  43.        (.FON)  file  which  contains  at  least  one  font  (.FNT).
  44.        Individual  .FNT  files  apparently  do  not  count  as font
  45.        resources.
  46.  
  47.        Creating the custom font:
  48.  
  49.        First,  you  can  use the Resource Workshop to create a .FNT
  50.        font  file.    RW can edit both .FNT and .FON files, but can
  51.        only create .FNT  files.  .FNT  files  are  individual fonts
  52.        while .FON files  are  collections  of  .FNT  files (usually
  53.        representing different  sizes  of  the  same  font).   Since
  54.        Windows  expects  .FON files, and  since  Resource  Workshop
  55.        creates  only  .FNT  files,  you  must  create   .FON  files
  56.        manually.  Once you have created a .FON file,  you  can  use
  57.        your new font(s) in your own applications!
  58.  
  59.        Constructing a font library:
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Resource Workshop                      NUMBER  :  737
  74.   VERSION  :  1.0
  75.        OS  :  WIN
  76.      DATE  :  February 25, 1992                        PAGE  :  2/5
  77.  
  78.     TITLE  :  Creating and Using Custom Fonts with Resource
  79.               Workshop
  80.  
  81.  
  82.  
  83.  
  84.        A font library is basically just a DLL with  an  empty  code
  85.        segment and a file extension of .FON.  You  may  choose  any
  86.        name for your font library up to eight letters.   Before you
  87.        begin, you will need the following:
  88.  
  89.            *  At least one .FNT font file  (possibly  created using
  90.               Resource Workshop)
  91.  
  92.            *  A .ASM file containing the empty code segment
  93.  
  94.            *  A  .RC  file  listing the fonts to be included in the
  95.               font library
  96.  
  97.            *  A .DEF file for the font library
  98.  
  99.        The .ASM empty code segment module:
  100.  
  101.        In  order to build the font library, you  need  to  have  at
  102.        least one code segment.  This segment should be empty.  Here
  103.        is some sample code that will do the trick:
  104.  
  105.             .model large
  106.             CODE SEGMENT
  107.             CODE ENDS
  108.             end
  109.  
  110.        You will need to create an empty .ASM file (give it the same
  111.        name  as your font) and insert this code.    Once  you  have
  112.        created this file, you will need to assemble it using:
  113.  
  114.             TASM XXXXXXXX.asm
  115.  
  116.        "XXXXXXXX" should be replaced  with  the  name of your font.
  117.        You have now created the empty code segment module.
  118.  
  119.        The .RC resource script file:
  120.  
  121.        You should create a new file with the extension '.RC'.  Give
  122.        the  file  the  same name as your font.  The  .RC  file  may
  123.        contain as many lines as you  wish.   Here is the format for
  124.        the file:
  125.  
  126.             1 FONT xxxxxxxx.FNT
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Resource Workshop                      NUMBER  :  737
  140.   VERSION  :  1.0
  141.        OS  :  WIN
  142.      DATE  :  February 25, 1992                        PAGE  :  3/5
  143.  
  144.     TITLE  :  Creating and Using Custom Fonts with Resource
  145.               Workshop
  146.  
  147.  
  148.  
  149.  
  150.             2 FONT yyyyyyyy.FNT
  151.                   :
  152.                   :
  153.  
  154.        "xxxxxxxx" and "yyyyyyyy"  are  the names of .FNT font files
  155.        that make up the individual fonts in the font library.
  156.  
  157.        The .DEF module definition file:
  158.  
  159.        The  module  definition  file should be a file with the same
  160.        name as your  font,  with  a  .DEF extension.  The .DEF file
  161.        should look like this:
  162.  
  163.             LIBRARY        XXXXXXXX
  164.             DESCRIPTION    'FONTRES yyyyyyy'
  165.             STUB           'WINSTUB.EXE'
  166.             DATA           NONE
  167.  
  168.        "XXXXXXXX"  should  be  the  UPPERCASE  name  of  your  font
  169.        library.  "yyyyyyyy" can be in one of three formats:
  170.  
  171.            -  aspect, logpixelsx, logpixelsy: comment
  172.  
  173.            -  CONTINUOUSSCALING: comment
  174.  
  175.            -  DEVICESPECIFIC devicetypegroup: comment
  176.  
  177.        See Chapter 18 of the Microsoft Windows Guide to Programming
  178.        book for details on each of these three formats.
  179.  
  180.        Putting it all together: Building the .FON file:
  181.  
  182.        There are essentially two  steps  to  building  the finished
  183.        .FON font library file:
  184.  
  185.           1.  Linking  the  empty   code  segment  module  into  an
  186.               'executable' .FON file
  187.  
  188.           2.  Adding the actual font resources to the library
  189.  
  190.        To link the empty code segment module into a .FON  file, you
  191.        can use the following command:
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.   PRODUCT  :  Resource Workshop                      NUMBER  :  737
  206.   VERSION  :  1.0
  207.        OS  :  WIN
  208.      DATE  :  February 25, 1992                        PAGE  :  4/5
  209.  
  210.     TITLE  :  Creating and Using Custom Fonts with Resource
  211.               Workshop
  212.  
  213.  
  214.  
  215.  
  216.             TLINK -Twd xxxxxxxx.obj, xxxxxxxx.fon,,,xxxxxxxx.def
  217.  
  218.        "xxxxxxxx" is the name  of  your font library.  Notice the -
  219.        Twd switch, which tells TLINK to form a Dynamic Link Library
  220.        (DLL).  Font libraries are really  just  resource-only DLL's
  221.        (which have no code).
  222.  
  223.        To  complete  the  .FON  file,  you  must  append  the  font
  224.        resources onto the font library.  This is done with:
  225.  
  226.             RC xxxxxxxx.rc xxxxxxxx.fon
  227.  
  228.        "xxxxxxxx" is the name of your font library.
  229.  
  230.   II. USING CUSTOM FONTS
  231.  
  232.        Congratulations!  You have now created a custom  font.   You
  233.        are almost certainly  ready  to use the custom font resource
  234.        in your own program.
  235.  
  236.        Loading the font:
  237.  
  238.        The first order of business is to get  Windows  to recognize
  239.        the  font.  This can be accomplished in  one  of  two  ways.
  240.        First, you can use the Windows Control Panel to add the font
  241.        to the list of  system  fonts.  Alternately, you can use the
  242.        function AddFontResource().   This function takes a filename
  243.        and causes Windows to  load  your font.  Don't forget to use
  244.        RemoveFontResource() when your program terminates.
  245.  
  246.        Using the font:
  247.  
  248.        First, you should initialize a  LOGFONT  structure  with the
  249.        information describing the font that you wish to  use.   Use
  250.        CreateFontIndirect to get a  handle  to  your  font (HFONT).
  251.        Once this HFONT is selected  into a device context, any text
  252.        output functions using that  device  context  will  use your
  253.        font.
  254.  
  255.        Cleanup:
  256.  
  257.        You should  use DeleteObject to remove the font (HFONT) when
  258.        you  are  finished  with  it.     Also,  if  you  have  used
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.   PRODUCT  :  Resource Workshop                      NUMBER  :  737
  272.   VERSION  :  1.0
  273.        OS  :  WIN
  274.      DATE  :  February 25, 1992                        PAGE  :  5/5
  275.  
  276.     TITLE  :  Creating and Using Custom Fonts with Resource
  277.               Workshop
  278.  
  279.  
  280.  
  281.  
  282.        AddFontResource   to   load   the